#include "GameMenu.h"

CGameMenu* CGameMenu::instance;

CGameMenu::CGameMenu()
{
	_choose=Start;
}
CGameMenu::~CGameMenu()
{

}
CGameMenu* CGameMenu::Singleton()
{
	if (instance==NULL)
	{
		instance =new CGameMenu();
	}
	return instance;
}
bool CGameMenu::Game_Init()
{
	_background=_gr->LoadSurface("Images\\Menu.png",D3DCOLOR_ARGB(255,0,0,0));
	_spriteChose=new CSprites("Images\\Choose.png",155,40,3,1);
	_sound->AddFile(OTHERFILES,"MenuChange","Sounds\\MenuChange.wav",BASS_MUSIC_RAMPS);
	return true;
}
void CGameMenu::Game_Run(HWND hwd,DWORD tickPerFrame)
{	
	Game_Update(tickPerFrame);
	_gr->BeginRender(hwd,_background);
	_spriteChose->Render(550,300+(_choose*40),_choose);
	_gr->EndRender();
}
void CGameMenu::Game_Update(DWORD tickPerFrame)
{
	_dxInput->Pool_Keyboard();
	
	if(_dxInput->OnKeyDown(DIK_UP)&& _choose==Load)
	{
		_choose=Start;
		_sound->Play("MenuChange",false);
		return;
	}
	if((_dxInput->OnKeyDown(DIK_DOWN)&& _choose==Start) ||(_dxInput->OnKeyDown(DIK_UP)&& _choose==Quit))
	{
		_choose=Load;
		_sound->Play("MenuChange",false);
		return;
	}
	if(_dxInput->OnKeyDown(DIK_DOWN)&& _choose==Load)
	{
		_choose=Quit;
		_sound->Play("MenuChange",false);
		return;
	}
	if(_dxInput->OnKeyDown(DIK_RETURN))
	{
		switch(_choose)
		{
		case Start:
			CGameSate::state=GameState::Play;
			return;
		case Load:
			CGameSate::state=GameState::LoadGame;
			return;
		case Quit:
			PostQuitMessage(0);
			return;
		}
		
	}
}
void CGameMenu::Game_Reset()
{
	Game_End();
}

void CGameMenu::Game_End()
{
	instance=NULL;
}